package com.lagou.mr.nsort;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

public class NumberBean implements WritableComparable<NumberBean> {
    private Long index;
    private Long value;

    //准备构造方法


    public NumberBean() {
    }

    public NumberBean(Long value) {
        this.value = value;
    }


    public Long getValue() {
        return value;
    }

    public void setValue(Long value) {
        this.value = value;
    }

    public Long getIndex() {
        return index;
    }

    public void setIndex(Long index) {
        this.index = index;
    }

    //序列化方法
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(index);
        out.writeLong(value);
    }

    //反序列化方法
    @Override
    public void readFields(DataInput in) throws IOException {
        this.index = in.readLong();
        this.value = in.readLong();
    }

    //指定排序规则,我们希望按照总时长进行排序
    @Override
    public int compareTo(NumberBean o) {  //返回值三种：0：相等 1：小于 -1：大于
        return this.getValue().compareTo(o.getValue());
    }

    @Override
    public boolean equals(Object o) {
       return super.equals(o);
    }

    @Override
    public int hashCode() {
        return Objects.hash(getIndex(), getValue());
    }

    @Override
    public String toString() {
        return index +
                "\t" + value;
    }
}
